using System;
using System.Collections;
using System.Collections.Specialized;
using System.Data;
using System.Data.SqlTypes;
using System.Data.SqlClient;
using System.Text;
using ECommerce.DAL;


namespace Entity
{
	/// <summary>
	/// This object represents the Private Fields of TblCoupon.
	/// </summary>
	
	[System.ComponentModel.DataObject]
    public class TblCoupon : DatabaseUtility
    {
		#region TblCoupon Private Fields


		Int32 _couponId;
		String _couponName = String.Empty;
		String _couponDescription = String.Empty;
		Decimal _couponAmount;
		Decimal _minAmount;
		String _calculationIn = String.Empty;
		String _couponType = String.Empty;
		String _couponImageUrl = String.Empty;
		DateTime _createDate;
		DateTime _expireDate;
		Boolean _isActive;
		Boolean _isDeleted;
		Int32 _productBrandId;
		
		#endregion
		#region TblCoupon Constractor
		/// <summary>
        /// Creates an empty object of TblCoupon. 
        /// This is mainly used to create a new instance of TblCoupon to add a new TblCoupon.
        /// </summary>
		public TblCoupon(){}
		
				
		/// <summary>
        /// Used to retrieve employee information from database, 
        /// which is also used by Update method to save information of an existing TblCoupon.
        /// </summary>
		public TblCoupon
		(
			Int32 couponId,
			String couponName,
			String couponDescription,
			Decimal couponAmount,
			Decimal minAmount,
			String calculationIn,
			String couponType,
			String couponImageUrl,
			DateTime createDate,
			DateTime expireDate,
			Boolean isActive,
			Boolean isDeleted,
			Int32 productBrandId
		)
		{
			_couponId = couponId;	
			_couponName = couponName;	
			_couponDescription = couponDescription;	
			_couponAmount = couponAmount;	
			_minAmount = minAmount;	
			_calculationIn = calculationIn;	
			_couponType = couponType;	
			_couponImageUrl = couponImageUrl;	
			_createDate = createDate;	
			_expireDate = expireDate;	
			_isActive = isActive;	
			_isDeleted = isDeleted;	
			_productBrandId = productBrandId;	
		}
		
		#endregion
		#region TblCoupon Properties
		
		 /***********************************************************************************************
                                    -- PROPERTIES --        
         Contains all the properties representing the data fields of the current entity.
         ***********************************************************************************************/

        /// <summary>
        /// This is the Primary key value of the CouponId, which can't be assigned from the application,
        /// to ensure the data consistancy, by not letting the user to change the PK_Coupon to update the data of an another TblCoupon instance.
        /// For view or updation purpose, every TblCoupon will be retrieved thru the proper 'Get' method.
        /// </summary>
		
		public Int32 CouponId
		{
			get {return _couponId;}	
		}
		
				
		public String CouponName
		{
			get {return _couponName;}
			set {_couponName = value;}
		}

		public String CouponDescription
		{
			get {return _couponDescription;}
			set {_couponDescription = value;}
		}

		public Decimal CouponAmount
		{
			get {return _couponAmount;}
			set {_couponAmount = value;}
		}

		public Decimal MinAmount
		{
			get {return _minAmount;}
			set {_minAmount = value;}
		}

		public String CalculationIn
		{
			get {return _calculationIn;}
			set {_calculationIn = value;}
		}

		public String CouponType
		{
			get {return _couponType;}
			set {_couponType = value;}
		}

		public String CouponImageUrl
		{
			get {return _couponImageUrl;}
			set {_couponImageUrl = value;}
		}

		public DateTime CreateDate
		{
			get {return _createDate;}
			set {_createDate = value;}
		}

		public DateTime ExpireDate
		{
			get {return _expireDate;}
			set {_expireDate = value;}
		}

		public Boolean IsActive
		{
			get {return _isActive;}
			set {_isActive = value;}
		}

		public Boolean IsDeleted
		{
			get {return _isDeleted;}
			set {_isDeleted = value;}
		}

		public Int32 ProductBrandId
		{
			get {return _productBrandId;}
			set {_productBrandId = value;}
		}
		

		#endregion
		#region TblCoupon Static Methods
		/************************************************************************************
                                    -- CREATE METHOD (STATIC) --
        *************************************************************************************/
		/************************* Architecure note:**********************************
        Note 1:
        This method is specially useful for the case, where we need to use Object Data Source controls.
        For ObjectDataSource/SqlDataSource controls, the insert/update metnod requires paramters methods, rather property based methods.
        However, there is still a way to pass property based objects as method parameter for data source controls, 
        but in that case we could not use Sql type, as view controls or asp parameter control can only contain few of primitive type.
        The main reason to remain the Sql Type in our object architecture is it is faster and contains better way for null value support.
        
        Note 2: 
        Non-primary key: it should be primitive type, as the asp paramter control (included in data source control) supports only primitive types.
        /*****************************************************************************/
		[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Insert, true)]
        public static  Int32 CreateNewTblCoupon
		(
			String couponName,
			String couponDescription,
			Decimal couponAmount,
			Decimal minAmount,
			String calculationIn,
			String couponType,
			String couponImageUrl,
			DateTime createDate,
			DateTime expireDate,
			Boolean isActive,
			Boolean isDeleted,
			Int32 productBrandId
		)
		{
			//creating an empty TblCoupon object
            TblCoupon tblCoupon = new TblCoupon();
				tblCoupon.CouponName = couponName;
				tblCoupon.CouponDescription = couponDescription;
				tblCoupon.CouponAmount = couponAmount;
				tblCoupon.MinAmount = minAmount;
				tblCoupon.CalculationIn = calculationIn;
				tblCoupon.CouponType = couponType;
				tblCoupon.CouponImageUrl = couponImageUrl;
				tblCoupon.CreateDate = createDate;
				tblCoupon.ExpireDate = expireDate;
				tblCoupon.IsActive = isActive;
				tblCoupon.IsDeleted = isDeleted;
				tblCoupon.ProductBrandId = productBrandId;
			
			return TblCoupon.CreateNewTblCoupon(tblCoupon);
		}
	
		/************************************************************************************
                 -- UPDATE METHODS (STATIC) --
        *************************************************************************************/

        /************************* Architecure note:**********************************
        Note 1:
        This method is specially useful for the case, where we need to use Object Data Source controls.
        For ObjectDataSource/SqlDataSource controls, the insert/update metnod requires paramters methods, rather property based methods.
        However, there is still a way to pass property based objects as method parameter for data source controls, 
        but in that case we could not use Sql type, as view controls or asp parameter control can only contain few of primitive type.
        The main reason to remain the Sql Type in our object architecture is it is faster and contains better way for null value support.
        
        Note 2: 
        There the two types of paramaters will be passed here.
         * a. Primary key paramater: it should be Sql type, as we will bind the primary key property for the view controls (form view, details view etc) as datakey.
         * b. Non-primary key: it should be primitive type, as the asp paramter control (included in data source control) supports only primitive types.
        /*****************************************************************************/
		
		[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, true)]
        public static  bool UpdateTblCoupon
		(
			Int32 couponId,
			String couponName,
			String couponDescription,
			Decimal couponAmount,
			Decimal minAmount,
			String calculationIn,
			String couponType,
			String couponImageUrl,
			DateTime createDate,
			DateTime expireDate,
			Boolean isActive,
			Boolean isDeleted,
			Int32 productBrandId
		)
		{
			 TblCoupon tblCoupon =  TblCoupon.GetTblCouponByCouponId(couponId);
			
				tblCoupon.CouponName = couponName;
				tblCoupon.CouponDescription = couponDescription;
				tblCoupon.CouponAmount = couponAmount;
				tblCoupon.MinAmount = minAmount;
				tblCoupon.CalculationIn = calculationIn;
				tblCoupon.CouponType = couponType;
				tblCoupon.CouponImageUrl = couponImageUrl;
				tblCoupon.CreateDate = createDate;
				tblCoupon.ExpireDate = expireDate;
				tblCoupon.IsActive = isActive;
				tblCoupon.IsDeleted = isDeleted;
				tblCoupon.ProductBrandId = productBrandId;
			
			return TblCoupon.UpdateTblCoupon(tblCoupon);
		}

		/************************************************************************************
                         -- DELETE METHODS --
        *************************************************************************************/
        /************************* Architecure note:**********************************
        We have used the employeeId parameter as SqlInt32, to bind the delete method with object data source and view control directly.
        ****************************************************************************/
		[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, true)]
        public static  bool DeleteTblCoupon
		(
			Int32 couponId
		)
		{
			//Validate Input
			if(couponId <= GetCouponIdMinValue)
				throw (new ArgumentOutOfRangeException("couponId"));
				
			// Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
			AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
			AddParameterToSqlCmd(sqlCmd, "@CouponId",SqlDbType.Int, 0, ParameterDirection.Input, couponId);
			SetCommandType(sqlCmd,CommandType.StoredProcedure,SPR_TBLCOUPON_DELETETBLCOUPON);
			ExecuteScalarCmd(sqlCmd);
			int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
			return (returnValue == 0 ? false : true);
			
		}
		
		/// <summary>
        /// Deletes a set of employees from the database.
        /// </summary>
		public static bool DeleteTblCouponList( System.Collections.Generic.List<Int32>  couponIdListToDelete)
		{
			//Validate Input
			foreach (Int32 couponId in couponIdListToDelete)
			    if(couponId <= GetCouponIdMinValue)
					throw (new ArgumentOutOfRangeException("couponId"));
			
			//performing deletion operation //

            string xmlString = FormatXMLForIdArray(couponIdListToDelete);
			
			// Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
			AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            AddParameterToSqlCmd(sqlCmd, "@CouponIdList", SqlDbType.Xml, xmlString.ToString().Length, ParameterDirection.Input, xmlString.ToString());
			SetCommandType(sqlCmd,CommandType.StoredProcedure,SPR_TBLCOUPON_DELETETBLCOUPONLIST);
			ExecuteScalarCmd(sqlCmd);
			int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
			return (returnValue == couponIdListToDelete.Count ? true : false);
		}
		
		/************************************************************************************
                                 -- GET BY PRIMARY METHODS --
        *************************************************************************************/
        /************************* Architecure note:**********************************
        Retrives an Employee from database, based on it's primary key.
        To view or update an employee, everytime we must have to use this type of 'get' method, 
        since we don't have direct access to the Primary key value for assigning value.
        We have used the employeeId parameter as SqlInt32, to bind the delete method with object data source and view control directly.
        /*****************************************************************************/
		[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
		public static TblCoupon GetTblCouponByCouponId(Int32 couponId)
		{
			if(couponId <= GetCouponIdMinValue)
					throw (new ArgumentOutOfRangeException("couponId"));
				
		 	// Execute SQL Command
			SqlCommand sqlCmd = new SqlCommand();
			AddParameterToSqlCmd(sqlCmd, "@CouponId",SqlDbType.Int, 0, ParameterDirection.Input, couponId);
			SetCommandType(sqlCmd,CommandType.StoredProcedure,SPR_TBLCOUPON_GETTBLCOUPONBYCOUPONID);
			GenerateCollectionFromReader test = new GenerateCollectionFromReader(GenerateTblCouponCollectionFromReader);
            CustomCollection<TblCoupon> objCollection = ((CustomCollection<TblCoupon>)ExecuteReaderCmd(sqlCmd, test));

            if (objCollection.Count > 0)
                return objCollection[0];
            else
                return null;
		}
		
		/************************************************************************************
                         -- GET BY FOREIGN KEY METHODS --
        *************************************************************************************/
				
		[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, false)]
		public static CustomCollection<TblCoupon> GetTblCouponByProductBrandId(Int32 productBrandId)
		{
			if(productBrandId <= GetProductBrandIdMinValue)
					throw (new ArgumentOutOfRangeException("productBrandId"));
				
		 	// Execute SQL Command
			SqlCommand sqlCmd = new SqlCommand();
			AddParameterToSqlCmd(sqlCmd, "@ProductBrandId",SqlDbType.Int, 0, ParameterDirection.Input, productBrandId);
			SetCommandType(sqlCmd,CommandType.StoredProcedure,SPR_TBLCOUPON_GETTBLCOUPONBYPRODUCTBRANDID);
			GenerateCollectionFromReader test = new GenerateCollectionFromReader(GenerateTblCouponCollectionFromReader);
            CustomCollection<TblCoupon> objCollection = ((CustomCollection<TblCoupon>)ExecuteReaderCmd(sqlCmd, test));

            if (objCollection.Count > 0)
                return objCollection;
            else
                return null;
		}
		
		/// <summary>
        /// Gets all the TblCoupon regarding 'PREFERRED_LANGUAGE_ID' foreign key.
        /// It supports efficient paging.
        /// </summary>
        /// <returns>A collection of TblCoupon.</returns>
		[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, false)]
        public static CustomCollection<TblCoupon> GetTblCouponByProductBrandIdPaged(Int32 productBrandId,String orderBy, Int32 startRowIndex, Int32 maximumRows)
		{
            //Validate Input
			if(productBrandId <= GetProductBrandIdMinValue)
					throw (new ArgumentOutOfRangeException("productBrandId"));
			
            if (orderBy == "")
                orderBy = "ProductBrandId";

            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
			AddParameterToSqlCmd(sqlCmd, "@ProductBrandId",SqlDbType.Int, 0, ParameterDirection.Input, productBrandId);
            AddParameterToSqlCmd(sqlCmd, "@orderby", SqlDbType.VarChar, 50, ParameterDirection.Input, orderBy);
            AddParameterToSqlCmd(sqlCmd, "@startrow", SqlDbType.Int, 0, ParameterDirection.Input, startRowIndex);
            AddParameterToSqlCmd(sqlCmd, "@pagesize", SqlDbType.Int, 0, ParameterDirection.Input, maximumRows);

            SetCommandType(sqlCmd,CommandType.StoredProcedure,SPR_TBLCOUPON_GETTBLCOUPONBYPRODUCTBRANDIDPAGED);

            GenerateCollectionFromReader test = new GenerateCollectionFromReader(GenerateTblCouponCollectionFromReader);
            CustomCollection<TblCoupon> objCollection = ((CustomCollection<TblCoupon>)ExecuteReaderCmd(sqlCmd, test));

            return objCollection;
        }
		
		/// <summary>
        /// This is a supporting method of 'GetEmployeeByPREFERRED_LANGUAGE_IDPagedPagedCountPaged' method.
        /// Used in paging, which returns the total number of records, returned from the ''GetEmployeeByReportsToPaged'' method (regardless of page size).
        /// Although we are not using the parameters, but we need the same signature as ''GetEmployeeByReportsToPaged'' to support paging.
        /// </summary>
		public static int GetTblCouponByProductBrandIdPagedCount(Int32 productBrandId,String orderBy, Int32 startRowIndex, Int32 maximumRows)
        {
            //Validate Input
			if(productBrandId <= GetProductBrandIdMinValue)
					throw (new ArgumentOutOfRangeException("productBrandId"));
			
			// Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
			AddParameterToSqlCmd(sqlCmd, "@ProductBrandId",SqlDbType.Int, 0, ParameterDirection.Input, productBrandId);
			AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            SetCommandType(sqlCmd,CommandType.StoredProcedure,SPR_TBLCOUPON_GETTBLCOUPONBYPRODUCTBRANDIDPAGEDCOUNT);
            ExecuteScalarCmd(sqlCmd);

            int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
            return returnValue;
        }
		
		/************************************************************************************
                 -- GET ALL METHODS --
        *************************************************************************************/
		[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public static CustomCollection<TblCoupon> GetAllTblCoupon()
		{
		
		 	// Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            SetCommandType(sqlCmd,CommandType.StoredProcedure,SPR_TBLCOUPON_GETALLTBLCOUPON);
            GenerateCollectionFromReader test = new GenerateCollectionFromReader(GenerateTblCouponCollectionFromReader);
            CustomCollection<TblCoupon> objCollection = ((CustomCollection<TblCoupon>)ExecuteReaderCmd(sqlCmd, test));

            return objCollection;
		}
		
		[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public static CustomCollection<TblCoupon> GetAllTblCouponPaged(String orderBy, Int32 startRowIndex, Int32 maximumRows)
        {
            //Validate Input
            if (orderBy == "")
                orderBy = "CouponId";

            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            AddParameterToSqlCmd(sqlCmd, "@orderby", SqlDbType.VarChar, 50, ParameterDirection.Input, orderBy);
            AddParameterToSqlCmd(sqlCmd, "@startrow", SqlDbType.Int, 0, ParameterDirection.Input, startRowIndex);
            AddParameterToSqlCmd(sqlCmd, "@pagesize", SqlDbType.Int, 0, ParameterDirection.Input, maximumRows);

            SetCommandType(sqlCmd,CommandType.StoredProcedure,SPR_TBLCOUPON_GETALLTBLCOUPONPAGED);

            GenerateCollectionFromReader test = new GenerateCollectionFromReader(GenerateTblCouponCollectionFromReader);
            CustomCollection<TblCoupon> objCollection = ((CustomCollection<TblCoupon>)ExecuteReaderCmd(sqlCmd, test));
            return objCollection;
        }
		
		[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public static int GetAllTblCouponPagedCount(String orderBy, Int32 startRowIndex, Int32 maximumRows)
        {
            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();

            AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            SetCommandType(sqlCmd,CommandType.StoredProcedure,SPR_TBLCOUPON_GETALLTBLCOUPONPAGEDCOUNT);
            ExecuteScalarCmd(sqlCmd);

            int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
            return returnValue;
        }
		
		#endregion
		#region Employee Instance Methods
		/************************************************************************************
                                    -- SAVE (INSERT/UPDATE) METHODS (INSTANCE) --
        *************************************************************************************/
		/// <summary>
        /// Saves (inserts and updates) an Employee into database.
        /// The insertion occur if the EmployeeId conatins default value.
        /// Otherwises it updates the Employee into the database, based on the primary key value stored in EmployeeId.
        /// This technique ensures an Employee will not be updated without having a valid EmployeeId.
        /// </summary>
		public bool Save()
		{
			if(CouponId<= GetCouponIdMinValue)
			{
				Int32 TempId=CreateNewTblCoupon(this);
				if(TempId>0)
				{
					_couponId=TempId;
					return true;
				}
				else
				{
					// error occurs
					return false;
				}
			}
			else
			{	//This is a update Command
				return (UpdateTblCoupon(this));
			}
			
		}
		
		public static Int32 CreateNewTblCoupon(TblCoupon newTblCoupon)
		{
			// validate Parameters
			if (newTblCoupon == null)
				throw (new ArgumentNullException("newTblCoupon"));

			// Execute SQL Command
			SqlCommand sqlCmd = new SqlCommand();
			int length = 0;
			AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            
			AddParameterToSqlCmd(sqlCmd, "@CouponName",SqlDbType.NVarChar, 500, ParameterDirection.Input, newTblCoupon.CouponName);
			AddParameterToSqlCmd(sqlCmd, "@CouponDescription",SqlDbType.NVarChar, 4000, ParameterDirection.Input, newTblCoupon.CouponDescription);
			AddParameterToSqlCmd(sqlCmd, "@CouponAmount",SqlDbType.Decimal, 9, ParameterDirection.Input, newTblCoupon.CouponAmount);
			AddParameterToSqlCmd(sqlCmd, "@MinAmount",SqlDbType.Decimal, 9, ParameterDirection.Input, newTblCoupon.MinAmount);
			AddParameterToSqlCmd(sqlCmd, "@CalculationIn",SqlDbType.NVarChar, 50, ParameterDirection.Input, newTblCoupon.CalculationIn);
			AddParameterToSqlCmd(sqlCmd, "@CouponType",SqlDbType.NVarChar, 50, ParameterDirection.Input, newTblCoupon.CouponType);
			AddParameterToSqlCmd(sqlCmd, "@CouponImageUrl",SqlDbType.NVarChar, 500, ParameterDirection.Input, newTblCoupon.CouponImageUrl);
			AddParameterToSqlCmd(sqlCmd, "@CreateDate",SqlDbType.DateTime, 0, ParameterDirection.Input, newTblCoupon.CreateDate);
			AddParameterToSqlCmd(sqlCmd, "@ExpireDate",SqlDbType.DateTime, 0, ParameterDirection.Input, newTblCoupon.ExpireDate);
			AddParameterToSqlCmd(sqlCmd, "@IsActive",SqlDbType.Bit, 0, ParameterDirection.Input, newTblCoupon.IsActive);
			AddParameterToSqlCmd(sqlCmd, "@IsDeleted",SqlDbType.Bit, 0, ParameterDirection.Input, newTblCoupon.IsDeleted);
			AddParameterToSqlCmd(sqlCmd, "@ProductBrandId",SqlDbType.Int, 0, ParameterDirection.Input, newTblCoupon.ProductBrandId);
			
			SetCommandType(sqlCmd,CommandType.StoredProcedure,SPR_TBLCOUPON_CREATENEWTBLCOUPON);
			ExecuteScalarCmd(sqlCmd);
			return (Int32.Parse(sqlCmd.Parameters["@ReturnValue"].Value.ToString()));

		}
		/// <summary>
        /// Updates an TblCoupon instance to the database.
        /// </summary>
		public static bool UpdateTblCoupon(TblCoupon newTblCoupon)
		{
			// validate Parameters
			if (newTblCoupon == null)
				throw (new ArgumentNullException("newTblCoupon"));

			// Execute SQL Command
			SqlCommand sqlCmd = new SqlCommand();
			int length = 0;
			AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            
			AddParameterToSqlCmd(sqlCmd, "@CouponId",SqlDbType.Int, 0, ParameterDirection.Input, newTblCoupon.CouponId);
			AddParameterToSqlCmd(sqlCmd, "@CouponName",SqlDbType.NVarChar, 500, ParameterDirection.Input, newTblCoupon.CouponName);
			AddParameterToSqlCmd(sqlCmd, "@CouponDescription",SqlDbType.NVarChar, 4000, ParameterDirection.Input, newTblCoupon.CouponDescription);
			AddParameterToSqlCmd(sqlCmd, "@CouponAmount",SqlDbType.Decimal, 9, ParameterDirection.Input, newTblCoupon.CouponAmount);
			AddParameterToSqlCmd(sqlCmd, "@MinAmount",SqlDbType.Decimal, 9, ParameterDirection.Input, newTblCoupon.MinAmount);
			AddParameterToSqlCmd(sqlCmd, "@CalculationIn",SqlDbType.NVarChar, 50, ParameterDirection.Input, newTblCoupon.CalculationIn);
			AddParameterToSqlCmd(sqlCmd, "@CouponType",SqlDbType.NVarChar, 50, ParameterDirection.Input, newTblCoupon.CouponType);
			AddParameterToSqlCmd(sqlCmd, "@CouponImageUrl",SqlDbType.NVarChar, 500, ParameterDirection.Input, newTblCoupon.CouponImageUrl);
			AddParameterToSqlCmd(sqlCmd, "@CreateDate",SqlDbType.DateTime, 0, ParameterDirection.Input, newTblCoupon.CreateDate);
			AddParameterToSqlCmd(sqlCmd, "@ExpireDate",SqlDbType.DateTime, 0, ParameterDirection.Input, newTblCoupon.ExpireDate);
			AddParameterToSqlCmd(sqlCmd, "@IsActive",SqlDbType.Bit, 0, ParameterDirection.Input, newTblCoupon.IsActive);
			AddParameterToSqlCmd(sqlCmd, "@IsDeleted",SqlDbType.Bit, 0, ParameterDirection.Input, newTblCoupon.IsDeleted);
			AddParameterToSqlCmd(sqlCmd, "@ProductBrandId",SqlDbType.Int, 0, ParameterDirection.Input, newTblCoupon.ProductBrandId);
			
			SetCommandType(sqlCmd,CommandType.StoredProcedure,SPR_TBLCOUPON_UPDATETBLCOUPON);
            ExecuteScalarCmd(sqlCmd);
			int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
			return (returnValue == 0 ? false : true);
		}
		#endregion
		
		#region TblCoupon Related Collections
		/// <summary>
        /// Creates and returns a strongly typed collection of Employee custom entity. 
        /// The colelction is created through iterating on the IdataReader object which contains Employee information, as a set of records, similar to tabular format.
        /// </summary>
		public static CollectionBase  GenerateTblCouponCollectionFromReader(IDataReader returnData) 
		{
			
			//creating the instance of Employee collection
			CustomCollection<TblCoupon> colTblCoupon = new CustomCollection<TblCoupon>();
			
			/************************* Architecure note:**********************************
             * Below code includes the null value functionality to retieve the data which has nill value in database end.
             * Design consideration:
             * Besides general data fields, special care should be taken for primary keys, to assign '0'/defaultvalue, rather passing 'Null' value in constructor parameter.
             * Although we are considering sqldb tyoe data for the current data container, but while retireving data from database end, through datareader object, we need to cast data reader objects using .net primitive data type, 
             * rather using sqldb type to cast, since data reader objects don't support sql db type to be casted.
             *****************************************************************************/

            //Iterating thriugh the data reader, to generate Employee collection.

			//getting the Employee collection by iterating thru the data reader
			while (returnData.Read()) 
			{
				//passing the TblCoupon constructor parameters from the current instance of data reader fields.
				TblCoupon newTblCoupon = new TblCoupon
				(
					returnData["CouponId"]== System.DBNull.Value ? GetCouponIdMinValue : (Int32 ) returnData["CouponId"],
					returnData["CouponName"]== System.DBNull.Value ? string.Empty: (String ) returnData["CouponName"],
					returnData["CouponDescription"]== System.DBNull.Value ? string.Empty: (String ) returnData["CouponDescription"],
					returnData["CouponAmount"]== System.DBNull.Value ? 0: (Decimal ) returnData["CouponAmount"],
					returnData["MinAmount"]== System.DBNull.Value ? 0: (Decimal ) returnData["MinAmount"],
					returnData["CalculationIn"]== System.DBNull.Value ? string.Empty: (String ) returnData["CalculationIn"],
					returnData["CouponType"]== System.DBNull.Value ? string.Empty: (String ) returnData["CouponType"],
					returnData["CouponImageUrl"]== System.DBNull.Value ? string.Empty: (String ) returnData["CouponImageUrl"],
					returnData["CreateDate"]== System.DBNull.Value ? DateTime.MinValue: (DateTime ) returnData["CreateDate"],
					returnData["ExpireDate"]== System.DBNull.Value ? DateTime.MinValue: (DateTime ) returnData["ExpireDate"],
					returnData["IsActive"]== System.DBNull.Value ? false: (Boolean ) returnData["IsActive"],
					returnData["IsDeleted"]== System.DBNull.Value ? false: (Boolean ) returnData["IsDeleted"],
					returnData["ProductBrandId"]== System.DBNull.Value ? 0: (Int32 ) returnData["ProductBrandId"]

				);
				//adding the Employee to the collection
				colTblCoupon.Add(newTblCoupon);
			}
			
			//returns the collection of Companys 
			return (colTblCoupon);
		}
		
		#endregion
		#region Constants and Default Values
		
		public static Int32 GetCouponIdMinValue
		{
			get
			{
				return 0;
			}
		}
		public static Int32 GetProductBrandIdMinValue
		{
			get
			{
				return 0;
			}
		}
		
		//create method related contants
			internal const string SPR_TBLCOUPON_CREATENEWTBLCOUPON="spr_TblCoupon_CreateNewTblCoupon";
			internal const string SPR_TBLCOUPON_UPDATETBLCOUPON="spr_TblCoupon_UpdateTblCoupon";
			internal const string SPR_TBLCOUPON_DELETETBLCOUPON="spr_TblCoupon_DeleteTblCoupon";
			internal const string SPR_TBLCOUPON_DELETETBLCOUPONLIST="spr_TblCoupon_DeleteTblCouponList";
			internal const string SPR_TBLCOUPON_GETTBLCOUPONBYCOUPONID="spr_TblCoupon_GetTblCouponByCouponId";
			internal const string SPR_TBLCOUPON_GETTBLCOUPONBYPRODUCTBRANDID="spr_TblCoupon_GetTblCouponByProductBrandId";
			internal const string SPR_TBLCOUPON_GETTBLCOUPONBYPRODUCTBRANDIDPAGED="spr_TblCoupon_GetTblCouponByProductBrandIdPaged";
			internal const string SPR_TBLCOUPON_GETTBLCOUPONBYPRODUCTBRANDIDPAGEDCOUNT="spr_TblCoupon_GetTblCouponByProductBrandIdPagedCount";
			internal const string SPR_TBLCOUPON_GETALLTBLCOUPON="spr_TblCoupon_GetAllTblCoupon";
			internal const string SPR_TBLCOUPON_GETALLTBLCOUPONPAGED="spr_TblCoupon_GetAllTblCouponPaged";
			internal const string SPR_TBLCOUPON_GETALLTBLCOUPONPAGEDCOUNT="spr_TblCoupon_GetAllTblCouponPagedCount";
		
		#endregion
	}
}	
